<template>
 <div id="app">
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-table
            :data="currentData"
            style="width: 100%">
            <el-table-column
              prop="id"
              label="ID"
              width="180">
            </el-table-column>
            <el-table-column
              prop="author"
              label="姓名"
              width="180">
            </el-table-column>
            <el-table-column
              prop="title"
              label="标题">
            </el-table-column>
            <el-table-column
              prop="content"
              label="内容">
            </el-table-column>
          </el-table>
        </div>
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentpage"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
 </div>
</template>

<script>
/* eslint-disable */
export default {
  name: 'HelloWorld',
  data () {
    return {
      tableData: [],
      total: 0,
      pagesize: 10,
      loading: true,
      currentpage: 1,
      currentData: [],
      pagesizes: [10, 15, 20, 25, 30, 50]

    }
  },
  created: function() {
      this.loading = true
      this.$http.post("/article/getlist").then(res=>{
        this.tableData = res.data.items;
        this.total = res.data.total;
        this.currentpage = 1;
        this.currentData = this.getPage();
        this.loading = false;
      }).catch(res=>{
        console.log("err")
      });
  },
  methods: {  
    handleSizeChange(val) {
      this.pagesize = val;
      this.currentData = this.getPage();
    },
    handleCurrentChange(val) {
      this.currentpage = val;
      this.currentData = this.getPage();
    },
    getPage() {
      return this.tableData.filter((item, index) => index < this.pagesize * this.currentpage && index >= this.pagesize * (this.currentpage - 1))
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
